package cm.example.shoppingplatformspringboot.controller;


import cm.example.shoppingplatformspringboot.entity.Goods;
import cm.example.shoppingplatformspringboot.service.GoodsService;
import cm.example.shoppingplatformspringboot.utils.ProductResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {
    @Resource
    private GoodsService goodsService;

    // 商品列表
    @GetMapping("/goodsList")
    public ProductResult goodsList(int page, int size) {
        return goodsService.selectAll(page, size);
    }

    // 热销商品
    @GetMapping("/hottestGoods")
    public List<Goods> hottestGoods() {
        return goodsService.hottestGoods();
    }

    // 所有商品类型
    @GetMapping("/getAllShopGenres")
    public List<Map<String, Object>> getAllShopGenres() {
        return goodsService.getAllShopGenres();
    }

    // 根据商品类型获取商品列表
    @GetMapping("/getGoodsListByGenre")
    public ProductResult getGoodsListByGenre(@RequestParam String value, @RequestParam int page, @RequestParam int size) {
        return goodsService.getGoodsListByGenre(value, page, size);
    }

    // 搜索商品
    @GetMapping("/searchGoods")
    public ProductResult searchGoods(@RequestParam String input, @RequestParam int page, @RequestParam int size) {
        return goodsService.searchGoods(input, page, size);
    }

    // 搜索商品名称
    @GetMapping("/searchGoodsByName")
    public List<String> searchGoodsByName(@RequestParam String name) {
        return goodsService.searchGoodsByName(name);
    }

    // 根据商品ID获取商品详情
    @GetMapping("/fetchProductData")
    public Goods fetchProductData(@RequestParam Integer id) {
        return goodsService.fetchProductData(id);
    }
}
